DEPTH		= ../../..
topsrcdir	= @top_srcdir@
srcdir		= @srcdir@
VPATH		= @srcdir@

include $(DEPTH)/config/autoconf.mk

include $(topsrcdir)/toolkit/mozapps/installer/package-name.mk

PKG_INST_PATH =

CONFIG_DIR = instgen
SFX_MODULE = $(topsrcdir)/other-licenses/7zstub/firefox/7zSD.sfx
PRE_RELEASE_SUFFIX := ""
DEFINES += -DPRE_RELEASE_SUFFIX="$(PRE_RELEASE_SUFFIX)"

INSTALLER_FILES = \
	nsis/installer.nsi \
	nsis/uninstaller.nsi \
	nsis/shared.nsh \
	$(NULL)

BRANDING_FILES = \
	wizHeader.bmp \
	wizHeaderRTL.bmp \
	wizWatermark.bmp \
	$(NULL)

DEFINES += \
	-DAB_CD=$(AB_CD) \
	-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
	-DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
	-DMOZ_APP_VENDOR=$(MOZ_APP_VENDOR) \
	-DMOZ_APP_DISPLAYNAME=${MOZ_APP_DISPLAYNAME} \
	-DMOZILLA_VERSION=${MOZILLA_VERSION} \
	$(NULL)

include $(topsrcdir)/config/config.mk

ifdef LOCALE_MERGEDIR
PPL_LOCALE_ARGS = \
  --l10n-dir=$(LOCALE_MERGEDIR)/browser/installer \
  --l10n-dir=$(call EXPAND_LOCALE_SRCDIR,browser/locales)/installer \
  --l10n-dir=$(topsrcdir)/browser/locales/en-US/installer \
  $(NULL)
else
PPL_LOCALE_ARGS=$(call EXPAND_LOCALE_SRCDIR,browser/locales)/installer
endif

installer::
	$(MAKE) -C .. installer-stage
	$(MAKE) $(CONFIG_DIR)/setup.exe

# For building the uninstaller during the application build so it can be
# included for mar file generation.
uninstaller::
	$(RM) -r $(CONFIG_DIR)
	$(MKDIR) $(CONFIG_DIR)
	$(INSTALL) $(addprefix $(srcdir)/,$(INSTALLER_FILES)) $(CONFIG_DIR)
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) \
	  $(srcdir)/app.tag.in > $(CONFIG_DIR)/app.tag
ifdef BRANDING_FILES
	$(INSTALL) $(addprefix $(DIST)/branding/,$(BRANDING_FILES)) $(CONFIG_DIR)
endif
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) \
	  $(srcdir)/nsis/defines.nsi.in > $(CONFIG_DIR)/defines.nsi
	$(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \
	  --preprocess-locale $(topsrcdir) \
	  $(PPL_LOCALE_ARGS) $(AB_CD) $(CONFIG_DIR)

$(CONFIG_DIR)/setup.exe::
	$(RM) -r $(CONFIG_DIR)
	$(MKDIR) $(CONFIG_DIR)
	$(INSTALL) $(addprefix $(srcdir)/,$(INSTALLER_FILES)) $(CONFIG_DIR)
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) \
	  $(srcdir)/app.tag.in > $(CONFIG_DIR)/app.tag
ifdef BRANDING_FILES
	$(INSTALL) $(addprefix $(DIST)/branding/,$(BRANDING_FILES)) $(CONFIG_DIR)
endif
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) \
	  $(srcdir)/nsis/defines.nsi.in > $(CONFIG_DIR)/defines.nsi
	$(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \
	  --preprocess-locale $(topsrcdir) \
	  $(PPL_LOCALE_ARGS) $(AB_CD) $(CONFIG_DIR)

GARBARGE_DIRS += instgen

include $(topsrcdir)/config/rules.mk
include $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/makensis.mk
